/*
* Author: honrun
*/
#ifndef _DevicesTime_H_
#define _DevicesTime_H_

#include <stdint.h>


/* 判断是否为闰年 */
#define YEAR_LEAP(year) ((((year) % 4)      != 0) ? 0 : \
                         (((year) % 100)    != 0) ? 1 : \
                         (((year) % 400)    != 0) ? 0 : \
                         (((year) % 3200)   != 0) ? 1 : \
                         (((year) % 172800) != 0) ? 0 : 1)
/* 获取年份天数 */
#define DAYS_OF_THE_YEAR(year) (YEAR_LEAP(year) == 1 ? 366 : 365)
/* 获取月份天数 */
#define DAYS_OF_THE_MONTH(year, month) ((((month) == 2) && (YEAR_LEAP(year) == 1)) ? 29 : st_ucMonthDays[(month) - 1])


typedef struct{
    float UTC;
    int32_t year;
    uint8_t month  : 4;
    uint8_t day    : 5;
    uint8_t hour   : 5;
    uint8_t minute : 6;
    uint8_t second : 6;
    uint8_t week   : 3;
}TimeType;


void vStampToTime(TimeType *ptypeTime, int64_t lStamp, float fUTC);
int64_t lTimeToStamp(TimeType *ptypeTime);

int64_t lTimebaseGet(void);

void vTimestampSet(int64_t lUNIXTimestamp);
int64_t lTimestampGet(void);

void vTimeUTCSet(float cUTC);
float fTimeUTCGet(void);

char *pcStampToTimeStrings(int64_t lUNIXTimestamp);


#endif
